package {
	import flash.display.Sprite;
	import org.adobe.utils.ArrayUtil;
	
	public class TestArr extends Sprite {
		
		public function TestArr() {
			var arr:Array = [1,2,3];
			ArrayUtil.removeValueFromIndex(arr,0);
			trace(arr);
		}
		private function initArray():void{
			var book1:Object = {name:"As3",autor:"Kinda"};
			var book2:Object = {name:"Flex3",autor:"Kinda"};
			var book3:Object = {name:"AIR3",autor:"Da"};
			var book4:Object = {name:"RIA3",autor:"Da"};
			
			var books:Array = [book2,book1,book3,book4];
			var prices:Array = [100,200,300,400];
			
			
			/** 
			 * arr
			 * 对数组各项处理，返回重新构成新数组*/
			
			/**例1*/
			var newbook:Array =  books.map(mapNewList);
			//trace(newbook[2].autor)
			function mapNewList(item:*,index:int,books:Array):Object{
				var newbook:Object = {};
				newbook.name = item.name;
				newbook.autor= item.autor;
				newbook.price= prices[index];
				return newbook;
			}
			/**例2*/
			var arr:Array = ["one","two","three"];
			var upArr:Array = arr.map(toUpcase);
			//trace(upArr)
			function toUpcase(item:String, inedx:int, arr:Array):String{
				return (item.toUpperCase());
			}
			/**
			 * every
			 * 所有项是否满足某一条件
			 */
			var arr1:Array = new Array(1, 2, 4);
			var res1:Boolean = arr1.every(isNumeric);
			trace("isNumeric:", res1);
			
			var arr2:Array = new Array(1, 2, "ham");
			var res2:Boolean = arr2.every(isNumeric);
			trace("isNumeric:", res2);
			function isNumeric(element:*, index:int, arr:Array):Boolean {
				return (element is Number);
			}
			
			/**
			 * some
			 * 某些项满足某一条件
			 */
			trace("some方法:" + books.some(someHandler))
			function someHandler(item:*,index:uint,arr:Array):Boolean{
				if(item.autor == "Da") return true;
				return false;
			}
			
			/**
			 * filter
			 * 满足条件的项生成新数组
			 */
			var daArr:Array = books.filter(someHandler)
			//trace(daArr.length,daArr[0].autor);
			
			/**
			 * forEach
			 * 对数组的各项修改操作
			 */
			books.forEach(doChange);
			function doChange(item:*,index:uint,arr:Array):void{
				item.name = "Flash编程之" + item.name;
				if(item.autor == "Da"){
					item.autor = "Yufeng";
				}
			}
			for each(var item:* in books){
				trace(item.name,item.autor);
			}
		}
	}
}